home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDSearch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  5.0 KB  |  193 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDSearch - An XFCN to Search absolute minute, second, block
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/10/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDSearch.c
  11.     link -sn Main=CDSearch -sn STDIO=CDSearch ∂
  12.          -sn INTENV=CDSearch -rt XFCN=42 ∂
  13.          -m CDSearch CDSearch.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. void    ExtractBCD(char *, short *);
  28. OSErr    ASearch(XCmdBlockPtr, short, short, short, short, short);
  29.  
  30. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  31.  
  32.  
  33. /************************************************************************
  34.  *
  35.  *  Function:        CDSearch
  36.  *
  37.  *  Purpose:        Search absolute minute, second and block
  38.  *
  39.  *  Returns:        result of driver call to Search
  40.  *                    normally 0, but could have parameter error or
  41.  *                    other error if non-existent block is specified
  42.  *
  43.  *  Side Effects:
  44.  *
  45.  *  Description:    We need four parameters:
  46.  *                    1) a flag indicating whether to play or pause at
  47.  *                       this address
  48.  *                    2) the minute
  49.  *                    3) the second
  50.  *                    4) the block
  51.  *                    Get the ioRefNum by accessing the famous global
  52.  *                    set in CDOpen().
  53.  *                    Extract the minute, second and block and start
  54.  *                    Searching at that point.
  55.  *
  56.  ************************************************************************/
  57. pascal void
  58. CDSearch(paramPtr)
  59. XCmdBlockPtr    paramPtr;
  60. {
  61.     Str31    returnString;
  62.     OSErr    result;
  63.     short    minute;
  64.     short    second;
  65.     short    block;
  66.     short    ioRefNum;
  67.     Handle    refHandle;
  68.     short    flag;
  69.     
  70.     /* Must be four parameters */
  71.     if ((paramPtr->paramCount) != 4)
  72.     {
  73.         /* Report error in parameters by returning -1 */
  74.         NumToStr(paramPtr, (long) -1, &returnString);
  75.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  76.         return;
  77.     }
  78.     
  79.     /* Get the global ioRefNum and convert it. */
  80.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  81.     ioRefNum = atoi(*(refHandle));
  82.     DisposHandle(refHandle);
  83.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  84.     
  85.     /* First param is flag.  Convert it to a short */
  86.     flag = atoi(*(paramPtr->params[0]));
  87.     
  88.     /* Second param is minute.  Convert it to a pascal string */
  89.     ExtractBCD((char *)*(paramPtr->params[1]), &minute);
  90.     
  91.     /* Third param is second.  Convert it to a pascal string */
  92.     ExtractBCD((char *)*(paramPtr->params[2]), &second);
  93.     
  94.     /* Fourth param is block.  Convert it to a pascal string */
  95.     ExtractBCD((char *)*(paramPtr->params[3]), &block);
  96.     
  97.     result = ASearch(paramPtr, ioRefNum, flag, minute, second, block);
  98.     
  99.     /* Convert result to string & return it */
  100.     NumToStr(paramPtr, (long) result, &returnString);
  101.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  102. }
  103.  
  104. /************************************************************************
  105.  *
  106.  *  Function:        ExtractBCD
  107.  *
  108.  *  Purpose:        Extract number in BCD from PString
  109.  *
  110.  *  Returns:        nothing
  111.  *
  112.  *  Side Effects:    *track gets a new value
  113.  *
  114.  *  Description:    Extract number in BCD from Cstring "name".
  115.  *                    "name" is always of the form "XX", where XX
  116.  *                    ranges from "1"  to "99"
  117.  *
  118.  ************************************************************************/
  119. void
  120. ExtractBCD(name, number)
  121. char        *name;
  122. short        *number;
  123. {
  124.     short    t;
  125.         
  126.     t = 0;
  127.     while (*name != 0)
  128.     {
  129.         t *= 16;
  130.         t += *name - '0';
  131.         name++;
  132.     }
  133.     
  134.     *number = t;    
  135. }
  136.  
  137. /************************************************************************
  138.  *
  139.  *  Function:        ASearch
  140.  *
  141.  *  Purpose:        start Searching at an absolute minute, second, block
  142.  *
  143.  *  Returns:        OSErr.  Probably either
  144.  *                        noErr        everything's hunky-dory!
  145.  *                        paramErr    you messed up the call somehow.
  146.  *
  147.  *  Side Effects:    starts Search.  By default, this will Search until the
  148.  *                    end of the disc.
  149.  *
  150.  *  Description:    pass in the absolute minute, second and block in BCD.
  151.  *
  152.  ************************************************************************/
  153. OSErr
  154. ASearch(paramPtr, refNum, flag, minute, second, block)
  155. XCmdBlockPtr    paramPtr;
  156. short    refNum;
  157. short    flag;
  158. short    minute;
  159. short    second;
  160. short    block;
  161. {
  162.     CDParam    myPB;
  163.     short        playMode;
  164.     Handle        refHandle;
  165.     
  166.     /* Get the global ioRefNum and convert it. */
  167.     refHandle = GetGlobal(paramPtr, PLAYMODE);
  168.     playMode = atoi(*(refHandle));
  169.     DisposHandle(refHandle);
  170.     
  171.     myPB.ioCompletion = 0;
  172.     myPB.ioNamePtr = (char *) 0;
  173.     myPB.ioVRefNum = 1;
  174.     myPB.ioCRefNum = refNum;
  175.     myPB.csCode = ASEARCH;
  176.     
  177.     myPB.csParam[0] = 0;
  178.     myPB.csParam[1] = AMSFADDR;
  179.     myPB.csParam[2] = 0;            /* must be in BCD */
  180.     myPB.csParam[3] = (char) minute;    /* must be in BCD */
  181.     myPB.csParam[4] = (char) second;    /* must be in BCD */
  182.     myPB.csParam[5] = (char) block;    /* must be in BCD */
  183.     myPB.csParam[6] = 0;
  184.     myPB.csParam[7] = flag;
  185.     myPB.csParam[8] = 0;
  186.     myPB.csParam[9] = playMode;
  187.     return (PBControl(&myPB, false));
  188. }
  189.  
  190.  
  191. /* C routines for HyperCard callbacks */
  192. #include <XCmdGlue.inc.c>
  193.